package com.mayikt;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Author: maplefire
 * @Description: ArrayBlockingQueue
 * @Date: 2022/09/02 10:12
 */

public class Test02 {
    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue<String> blockingQueue = new ArrayBlockingQueue<String>(3);
        blockingQueue.offer("张三");
        blockingQueue.offer("李四", 3, TimeUnit.SECONDS); // 没满3，不会等待，直接入队
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll()); // 不会等待 没设置等待时间，取值null
        System.out.println(blockingQueue.poll(3, TimeUnit.SECONDS)); // 3秒后打印null
    }
}
